package com.heima.gametest;

import java.util.Random;

public class Gamer {
    private String name;
    private int blood;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public Gamer(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public Gamer() {
    }

    public void attack(Gamer gamer) {
        //定义伤害
        int hurt = new Random().nextInt(20) + 1;
        //定义剩余血量
        int newBlood = this.blood - hurt;
        //剩余血量判断
        newBlood = newBlood < 0 ? 0 : newBlood;
        //判断之后将血量重新赋值
        gamer.setBlood(newBlood);

        System.out.println(getName() + "举起拳头打了" + this.name + "一下，造成了" + hurt + "点伤害，"
                + this.name + "还剩下" + newBlood + "点血量");

    }
}
